public class Expressions {

	private Factors factor;
	private Expressions expression;
	private int value;

	public Expressions(Tokens tokens){
		this.factor = null;
		this.expression = null;
		this.parse(tokens);
	}
	
	public void parse(Tokens tokens) {
		this.factor = new Factors(tokens);
		// check for '+' or '-'
		if(tokens.getToken() == 22 || tokens.getToken() == 23){
			this.value = tokens.getToken();
			tokens.skipToken();
			this.expression = new Expressions(tokens);
		}
	}

	public int runExp() {
		int val = this.factor.runFac();
		if(this.expression != null){
			// the operation is '+'
			if(this.value == 22){
				val = val + this.expression.runExp();
			} else{ // the operation is '-'
				val = val - this.expression.runExp();
			}
		}
		return val;
	}
}